namespace SmartSoft.Lists
{
    using SmartSoft;
    using SmartSoft.Controls;
    using SmartSoft.ADP;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDmBpEditor : FormListEditor
    {
        private IContainer components;
        private LabelControl lblBP_Cuoi;
        private LabelControl lblBP_Cuoi0;
        private LabelControl lblMa_Bp;
        private LabelControl lblMa_Bp_Me;
        private LabelControl lblTen_Bp;
        private LabelControl lblTen_Bp_E;
        private TextOption txtBP_Cuoi;
        private TextControl txtMa_Bp;
        private TextSearch txtMa_Bp_Me;
        private TextControl txtTen_Bp;
        private TextControl txtTen_Bp_E;
        private TextControl txtTen_Bp_Me;

        public FormDmBpEditor()
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            //ComponentResourceManager manager = new ComponentResourceManager(typeof(FormDmBpEditor));
            this.txtMa_Bp = new TextControl();
            this.lblMa_Bp = new LabelControl();
            this.txtTen_Bp = new TextControl();
            this.lblTen_Bp = new LabelControl();
            this.txtTen_Bp_E = new TextControl();
            this.lblTen_Bp_E = new LabelControl();
            this.lblBP_Cuoi0 = new LabelControl();
            this.txtTen_Bp_Me = new TextControl();
            this.txtMa_Bp_Me = new TextSearch();
            this.txtBP_Cuoi = new TextOption();
            this.lblBP_Cuoi = new LabelControl();
            this.lblMa_Bp_Me = new LabelControl();
            base.SuspendLayout();
            base.txtMa_Loai3.FirstFilter = "Type = 'BP3'";
            base.txtMa_Loai3.Location = new Point(0x17b, 0x8a);
            base.txtMa_Loai3.TabIndex = 7;
            base.txtMa_Loai2.FirstFilter = "Type = 'BP2'";
            base.txtMa_Loai2.Location = new Point(0xfb, 0x8a);
            base.txtMa_Loai2.TabIndex = 6;
            base.txtMa_Loai1.FirstFilter = "Type = 'BP1'";
            base.txtMa_Loai1.Location = new Point(0x7b, 0x8a);
            base.txtMa_Loai1.TabIndex = 5;
            base.lblPhan_Loai.Location = new Point(12, 0x8d);
            this.txtMa_Bp.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Bp.CheckTextSearched = false;
            this.txtMa_Bp.DisabledForeColor = Color.Empty;
            this.txtMa_Bp.Font = new Font("Arial", 8.25f);
            this.txtMa_Bp.Location = new Point(0x7b, 0x1c);
            this.txtMa_Bp.MaxLength = 0x20;
            this.txtMa_Bp.Name = "txtMa_Bp";
            this.txtMa_Bp.OldValue = null;
            this.txtMa_Bp.Size = new Size(0x7e, 20);
            this.txtMa_Bp.TabIndex = 0;
            this.txtMa_Bp.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Bp.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Bp.Value = null;//manager.GetObject("txtMa_Bp.Value");
            this.lblMa_Bp.AutoSize = true;
            this.lblMa_Bp.Font = new Font("Arial", 8.25f);
            this.lblMa_Bp.Location = new Point(12, 0x1f);
            this.lblMa_Bp.Name = "lblMa_Bp";
            this.lblMa_Bp.Size = new Size(0x3f, 14);
            this.lblMa_Bp.TabIndex = 4;
            this.lblMa_Bp.Text = "Mã bộ phận";
            this.txtTen_Bp.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Bp.CheckTextSearched = false;
            this.txtTen_Bp.DisabledForeColor = Color.Empty;
            this.txtTen_Bp.Font = new Font("Arial", 8.25f);
            this.txtTen_Bp.Location = new Point(0x7b, 50);
            this.txtTen_Bp.MaxLength = 0x80;
            this.txtTen_Bp.Name = "txtTen_Bp";
            this.txtTen_Bp.OldValue = null;
            this.txtTen_Bp.Size = new Size(0x17e, 20);
            this.txtTen_Bp.TabIndex = 1;
            this.txtTen_Bp.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtTen_Bp.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtTen_Bp.Value = null;//manager.GetObject("txtTen_Bp.Value");
            this.lblTen_Bp.AutoSize = true;
            this.lblTen_Bp.Font = new Font("Arial", 8.25f);
            this.lblTen_Bp.Location = new Point(12, 0x35);
            this.lblTen_Bp.Name = "lblTen_Bp";
            this.lblTen_Bp.Size = new Size(0x43, 14);
            this.lblTen_Bp.TabIndex = 4;
            this.lblTen_Bp.Text = "Tên bộ phận";
            this.txtTen_Bp_E.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Bp_E.CheckTextSearched = false;
            this.txtTen_Bp_E.DisabledForeColor = Color.Empty;
            this.txtTen_Bp_E.Font = new Font("Arial", 8.25f);
            this.txtTen_Bp_E.Location = new Point(0x7b, 0x48);
            this.txtTen_Bp_E.MaxLength = 0x80;
            this.txtTen_Bp_E.Name = "txtTen_Bp_E";
            this.txtTen_Bp_E.OldValue = null;
            this.txtTen_Bp_E.Size = new Size(0x17e, 20);
            this.txtTen_Bp_E.TabIndex = 2;
            this.txtTen_Bp_E.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtTen_Bp_E.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtTen_Bp_E.Value = null;//manager.GetObject("txtTen_Bp_E.Value");
            this.lblTen_Bp_E.AutoSize = true;
            this.lblTen_Bp_E.Font = new Font("Arial", 8.25f);
            this.lblTen_Bp_E.Location = new Point(12, 0x4b);
            this.lblTen_Bp_E.Name = "lblTen_Bp_E";
            this.lblTen_Bp_E.Size = new Size(0x4a, 14);
            this.lblTen_Bp_E.TabIndex = 4;
            this.lblTen_Bp_E.Text = "Tên tiếng Anh";
            this.lblBP_Cuoi0.AutoSize = true;
            this.lblBP_Cuoi0.Font = new Font("Arial", 8.25f);
            this.lblBP_Cuoi0.ForeColor = Color.Blue;
            this.lblBP_Cuoi0.Location = new Point(0x98, 0x61);
            this.lblBP_Cuoi0.Name = "lblBP_Cuoi0";
            this.lblBP_Cuoi0.Size = new Size(0x9b, 14);
            this.lblBP_Cuoi0.TabIndex = 0x29;
            this.lblBP_Cuoi0.Text = "C-Bộ phận cuối, K-Bộ phận mẹ";
            this.txtTen_Bp_Me.BackColor = SystemColors.Control;
            this.txtTen_Bp_Me.BorderStyle = BorderStyle.None;
            this.txtTen_Bp_Me.CheckTextSearched = false;
            this.txtTen_Bp_Me.DisabledForeColor = Color.Blue;
            this.txtTen_Bp_Me.Enabled = false;
            this.txtTen_Bp_Me.Font = new Font("Arial", 8.25f);
            this.txtTen_Bp_Me.ForeColor = Color.Blue;
            this.txtTen_Bp_Me.Location = new Point(0xff, 0x77);
            this.txtTen_Bp_Me.Name = "txtTen_Bp_Me";
            this.txtTen_Bp_Me.OldValue = null;
            this.txtTen_Bp_Me.Size = new Size(250, 13);
            this.txtTen_Bp_Me.TabIndex = 40;
//            this.txtTen_Bp_Me.Value = null;//manager.GetObject("txtTen_Bp_Me.Value");
            this.txtMa_Bp_Me.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Bp_Me.CheckTextSearched = false;
            this.txtMa_Bp_Me.DisabledForeColor = Color.Empty;
            this.txtMa_Bp_Me.EmptyIsValid = true;
            this.txtMa_Bp_Me.FieldDisplay = "Ten_Bp";
            this.txtMa_Bp_Me.FirstFilter = "BP_Cuoi = 'K'";
            this.txtMa_Bp_Me.Font = new Font("Arial", 8.25f);
            this.txtMa_Bp_Me.Location = new Point(0x7b, 0x74);
            this.txtMa_Bp_Me.MaxLength = 0x20;
            this.txtMa_Bp_Me.Name = "txtMa_Bp_Me";
            this.txtMa_Bp_Me.OldValue = null;
            this.txtMa_Bp_Me.Size = new Size(0x7e, 20);
            this.txtMa_Bp_Me.TabIndex = 4;
            this.txtMa_Bp_Me.TableName = "DMBP";
            this.txtMa_Bp_Me.TextDisplay = this.txtTen_Bp_Me;
            this.txtMa_Bp_Me.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Bp_Me.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Bp_Me.Value = null;//manager.GetObject("txtMa_Bp_Me.Value");
            this.txtBP_Cuoi.CharacterCasing = CharacterCasing.Upper;
            this.txtBP_Cuoi.CheckTextSearched = false;
            this.txtBP_Cuoi.DisabledForeColor = Color.Empty;
            this.txtBP_Cuoi.Font = new Font("Arial", 8.25f);
            this.txtBP_Cuoi.InputMask = "C,K";
            this.txtBP_Cuoi.Location = new Point(0x7b, 0x5e);
            this.txtBP_Cuoi.Name = "txtBP_Cuoi";
            this.txtBP_Cuoi.OldValue = null;
            this.txtBP_Cuoi.Size = new Size(0x17, 20);
            this.txtBP_Cuoi.TabIndex = 3;
            this.txtBP_Cuoi.Text = "C";
            this.txtBP_Cuoi.Value = "C";
            this.lblBP_Cuoi.AutoSize = true;
            this.lblBP_Cuoi.Font = new Font("Arial", 8.25f);
            this.lblBP_Cuoi.Location = new Point(12, 0x61);
            this.lblBP_Cuoi.Name = "lblBP_Cuoi";
            this.lblBP_Cuoi.Size = new Size(70, 14);
            this.lblBP_Cuoi.TabIndex = 0x25;
            this.lblBP_Cuoi.Text = "Bộ phận cuối";
            this.lblMa_Bp_Me.AutoSize = true;
            this.lblMa_Bp_Me.Font = new Font("Arial", 8.25f);
            this.lblMa_Bp_Me.Location = new Point(12, 0x77);
            this.lblMa_Bp_Me.Name = "lblMa_Bp_Me";
            this.lblMa_Bp_Me.Size = new Size(0x40, 14);
            this.lblMa_Bp_Me.TabIndex = 0x26;
            this.lblMa_Bp_Me.Text = "Bộ phận mẹ";
            base.AddTitleText = "Thêm mới bộ phận";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.ClientSize = new Size(0x20a, 0xac);
            base.Controls.Add(this.lblBP_Cuoi0);
            base.Controls.Add(this.txtTen_Bp_Me);
            base.Controls.Add(this.txtMa_Bp_Me);
            base.Controls.Add(this.txtBP_Cuoi);
            base.Controls.Add(this.lblBP_Cuoi);
            base.Controls.Add(this.lblMa_Bp_Me);
            base.Controls.Add(this.lblTen_Bp_E);
            base.Controls.Add(this.lblTen_Bp);
            base.Controls.Add(this.lblMa_Bp);
            base.Controls.Add(this.txtTen_Bp_E);
            base.Controls.Add(this.txtTen_Bp);
            base.Controls.Add(this.txtMa_Bp);
            base.EditTitleText = "Sửa bộ phận";
            base.FirstFreeCode = "BP1";
            base.Name = "FormDmBpEditor";
            base.SecondFreeCode = "BP2";
            this.Text = "Thêm mới bộ phận";
            base.ThirdFreeCode = "BP3";
            base.Controls.SetChildIndex(base.lblPhan_Loai, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai1, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai2, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai3, 0);
            base.Controls.SetChildIndex(this.txtMa_Bp, 0);
            base.Controls.SetChildIndex(this.txtTen_Bp, 0);
            base.Controls.SetChildIndex(this.txtTen_Bp_E, 0);
            base.Controls.SetChildIndex(this.lblMa_Bp, 0);
            base.Controls.SetChildIndex(this.lblTen_Bp, 0);
            base.Controls.SetChildIndex(this.lblTen_Bp_E, 0);
            base.Controls.SetChildIndex(this.lblMa_Bp_Me, 0);
            base.Controls.SetChildIndex(this.lblBP_Cuoi, 0);
            base.Controls.SetChildIndex(this.txtBP_Cuoi, 0);
            base.Controls.SetChildIndex(this.txtMa_Bp_Me, 0);
            base.Controls.SetChildIndex(this.txtTen_Bp_Me, 0);
            base.Controls.SetChildIndex(this.lblBP_Cuoi0, 0);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        protected override void OnReset()
        {
            this.txtBP_Cuoi.ReadOnly = !base.NewChecked;
            base.OnReset();
        }

        public override bool OnSave()
        {
            DataRow localCurrentRow;
            if (string.IsNullOrEmpty(this.txtMa_Bp.Text))
            {
                MessageBox.Show("Chưa nhập mã bộ phận!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (string.IsNullOrEmpty(this.txtTen_Bp.Text))
            {
                MessageBox.Show("Chưa nhập tên bộ phận!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (base.NewChecked)
            {
                localCurrentRow = base.LocalTable.NewRow();
            }
            else
            {
                localCurrentRow = base.LocalCurrentRow;
            }
            localCurrentRow["Ma_Bp"] = this.txtMa_Bp.Value;
            localCurrentRow["Ten_Bp"] = this.txtTen_Bp.Value;
            localCurrentRow["Ten_Bp_E"] = this.txtTen_Bp_E.Value;
            localCurrentRow["BP_Cuoi"] = this.txtBP_Cuoi.Value;
            localCurrentRow["Ma_Bp_Me"] = this.txtMa_Bp_Me.Value;
            localCurrentRow["Ten_Bp_Me"] = this.txtTen_Bp_Me.Value;
            localCurrentRow["Ma_Loai1"] = base.txtMa_Loai1.Value;
            localCurrentRow["Ma_Loai2"] = base.txtMa_Loai2.Value;
            localCurrentRow["Ma_Loai2"] = base.txtMa_Loai2.Value;
            DmBpDataAccess access = new DmBpDataAccess();
            if (base.ShowMessage(localCurrentRow, access.SaveRow(base.NewChecked, localCurrentRow)))
            {
                return false;
            }
            if (base.NewChecked)
            {
                base.LocalTable.Rows.Add(localCurrentRow);
            }
            base.LocalCurrentRow = localCurrentRow;
            base.LocalTable.AcceptChanges();
            this.txtMa_Bp.Focus();
            return base.OnSave();
        }

        public override void OnShow()
        {
            this.txtMa_Bp.Value = base.LocalCurrentRow["Ma_Bp"];
            this.txtTen_Bp.Value = base.LocalCurrentRow["Ten_Bp"];
            this.txtTen_Bp_E.Value = base.LocalCurrentRow["Ten_Bp_E"];
            this.txtBP_Cuoi.Value = base.LocalCurrentRow["BP_Cuoi"];
            this.txtMa_Bp_Me.Value = base.LocalCurrentRow["Ma_Bp_Me"];
            this.txtTen_Bp_Me.Value = base.LocalCurrentRow["Ten_Bp_Me"];
            base.txtMa_Loai1.Value = base.LocalCurrentRow["Ma_Loai1"];
            base.txtMa_Loai2.Value = base.LocalCurrentRow["Ma_Loai2"];
            base.txtMa_Loai2.Value = base.LocalCurrentRow["Ma_Loai2"];
            base.OnShow();
        }
    }
}

